package com.maochang.controller;

import com.maochang.pojo.util.Result;
import com.maochang.pojo.util.TreeNode;
import com.maochang.service.PsFunctionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/JueSeShouQuan")
public class JueSeShouQuan {
    String msg;

    @Resource
    private PsFunctionService psFunctionService;

    @GetMapping("/searchTreeData")
    public Result searchTreeData(Integer roleId){
       List<TreeNode> list= psFunctionService.searchTreeData(roleId);
        return Result.success(list);
    }
    @PostMapping("/grant")
    public Result grant(Integer roleId,String[] functionid){
        try {
            psFunctionService.grant(roleId,functionid);
            msg="角色授权成功";
            return Result.success(msg);
        }catch (Exception ex){
            msg="角色授权失败";
            log.error(msg,ex);
            return Result.fail(msg,ex);
        }
    }
}
